package top.kaoshanji.t1ch10b;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 代码清单-t1ch10b-210页a：将对象作为响应体发送
 * @author kaoshanji
 * ^_^
 * create time 2025/4/30 18:41
 */
@RestController
public class CountryController {

    @GetMapping("/france")
    public Country france() {
        return Country.of("France", 67);
    }

    @GetMapping("/countryList")
    public List<Country> countryList() {
        Country country1 = Country.of("France", 67);
        Country country2 = Country.of("Spain", 47);

        return List.of(country1, country2);
    }

    /**
     * 代码清单-t1ch10b-213页a：添加自定义响应头并设置响应状态
     * @return ResponseEntity
     */
    @GetMapping("/franceResponse")
    public ResponseEntity<Country> franceResponse() {
        Country country = Country.of("France", 67);

        return ResponseEntity.status(HttpStatus.ACCEPTED)
                .header("continent", "Europe")
                .header("capital", "Paris")
                .header("favorite_food", "cheese and wine")
                .body(country);

    }


}
